// Variables that are used on both client and server
 
SWEP.PrintName      = "Roller Wand"     
SWEP.DrawAmmo         = false
SWEP.DrawCrosshair    = true
SWEP.ViewModelFOV	= 70
 
SWEP.Author   = "Valve"
SWEP.Contact        = "n/a"
SWEP.Purpose        = "Make Rollermines Friendly"
SWEP.Instructions   = "Primary=Friendly Rollermines Secondary=Normal Rollermines  Reload=Activate/Open Stuff"
SWEP.Category	    = "HL2 Beta Sweps"

SWEP.Spawnable      = false
SWEP.AdminSpawnable  = true      // Spawnable in singleplayer or by server admins
 
SWEP.ViewModel      = "models/weapons/v_stunbaton.mdl"
SWEP.WorldModel   = "models/weapons/w_stunbaton.mdl"

util.PrecacheModel("models/weapons/v_stunbaton.mdl")
util.PrecacheModel("models/weapons/w_stunbaton.mdl")
 
SWEP.Primary.ClipSize      = -1
SWEP.Primary.DefaultClip    = -1
SWEP.Primary.Automatic    = false
SWEP.Primary.Ammo         = "none"
 
SWEP.Secondary.ClipSize  = -1
SWEP.Secondary.DefaultClip  = -1
SWEP.Secondary.Automatic    = false
SWEP.Secondary.Ammo   = "none"
 
local ShootSound = Sound( "AlyxEMP.Discharge" )
//local ShootSound = Sound( "vo/npc/alyx/hurt05.wav" )

/*---------------------------------------------------------
    Initialize - Setting hold type
---------------------------------------------------------*/
function SWEP:Initialize()

	
end
 
/*---------------------------------------------------------
   Think does nothing
---------------------------------------------------------*/
function SWEP:Think()
end
 
 
/*---------------------------------------------------------
    PrimaryAttack - Everyone loves orange
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
 
 
//Rollermine detection :O
    local tr = self.Owner:GetEyeTrace() -- What's he looking at
if tr.HitWorld then return end --Dont turn the world invisible! Unfortunately
if tr.Entity:GetClass() != "npc_rollermine" then return end --wtf m8 this aint no roller
//Sounds messages and uh blah
 
  Msg("Rollermine converted! (orange)\n")
   
    self.Weapon:EmitSound( ShootSound )
    self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
    // The rest is only done on the server
    if (!SERVER) then return end
   
 	local effectdata = EffectData()
		effectdata:SetOrigin( tr.HitPos )
		effectdata:SetNormal( tr.HitNormal )
		effectdata:SetMagnitude( 8 )
		effectdata:SetScale( 1 )
		effectdata:SetRadius( 16 )
	util.Effect( "cball_bounce", effectdata )       tr.Entity:SetName( "friendlyroll" )
//Orange please mister
//    tr.Entity:SetSkin( 1 )
        tr.Entity:SetColor(199, 105, 0, 255)
// What NPCs the rollermine likes and dislikes
                tr.Entity:AddRelationship("npc_alyx D_LI 999")
                tr.Entity:AddRelationship("player D_LI 999")
//For some reason just adding combine_s makes it hate all combine.
                tr.Entity:AddRelationship("npc_combine_s D_HT 998")
                tr.Entity:AddRelationship("npc_metropolice D_HT 999")
                tr.Entity:AddRelationship("npc_zombie D_HT 999")
                tr.Entity:AddRelationship("friendlyroll D_LI 999")


//	end
end
/*---------------------------------------------------------
    SecondaryAttack - Back to blue
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
 
 
 
//Rollermine detection :O
    local tr = self.Owner:GetEyeTrace() -- What's he looking at
if tr.HitWorld then return end --Dont turn the world invisible! Unfortunately
if tr.Entity:GetClass() != "npc_rollermine" then return end --wtf m8 this aint no roller
//Sounds messages and uh blah
 
  Msg("Rollermine converted! (blue)\n")
   
    self.Weapon:EmitSound( ShootSound )
    self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )   
    // The rest is only done on the server
    if (!SERVER) then return end

 	local effectdata = EffectData()
		effectdata:SetOrigin( tr.HitPos )
		effectdata:SetNormal( tr.HitNormal )
		effectdata:SetMagnitude( 8 )
		effectdata:SetScale( 1 )
		effectdata:SetRadius( 16 )
	util.Effect( "cball_bounce", effectdata )       tr.Entity:SetName( "friendlyroll" )   
//Back to blue/default innit
        tr.Entity:SetColor(255, 255, 255, 255)
// What NPCs the rollermine likes and dislikes
                tr.Entity:AddRelationship("npc_alyx D_HT 999")
                tr.Entity:AddRelationship("player D_HT 999")
//For some reason just adding combine_s makes it fear all combine.
                tr.Entity:AddRelationship("npc_combine_s D_FR 998")
end 

function SWEP:Reload()
 
trace = {} -- Trace a line...
trace.start = self.Owner:GetShootPos() -- From the owner,
trace.endpos = trace.start + (self.Owner:GetAimVector() * 128) -- 128 units in front of the owner, and in the direction the owner is facing.
trace.filter = { self.Owner, self.Weapon } --Which entities will the traced line pass through?
tr = util.TraceLine( trace ) -- Actually trace the thing.
 
if (tr.HitNonWorld) then --If it hits something that isn't the map...
local enthit = tr.Entity -- "enthit" is whatever it hits.
 
// If "enthit" is a "normal" door, open it.
if (enthit:GetClass() == "func_door_rotating" or enthit:GetClass() == "prop_door_rotating") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Unlock", "", 0)
enthit:Fire("Open", "", 0.01)
end
 
// If "enthit" is like a garage door, do this
if (enthit:GetClass() == "func_door") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Unlock", "", 0)
enthit:Fire("Open", "", 0.01)
enthit:Fire("Toggle", "", 0.01)
end
 
// If "enthit" is a combine/elevator door, do this
if (enthit:GetClass() == "prop_dynamic" and enthit:GetModel() != "models/props_lab/RavenDoor.mdl") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("SetAnimation", "Open", 0)
end
 
// If "enthit" is a rollermine, do this
if (enthit:GetClass() == "NPC_rollermine") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Powerdown", "", 0)
end
 
// If "enthit" is a sliding door, do this
if (enthit:GetClass() == "func_movelinear") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("SetAnimation", "Open", 0)
end
 
// If "enthit" is an elevator, do this
if (enthit:GetClass() == "func_tracktrain") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Toggle", "", 0)
end
 
// If "enthit" is a prop, do this
if (enthit:GetClass() == "prop_physics") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("EnableMotion", "", 0)
end
 
// If "enthit" is the ravenholm door, do this
if (enthit:GetClass() == "prop_dynamic" and enthit:GetModel() == "models/props_lab/RavenDoor.mdl") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("SetAnimation", "RavenDoor_Open", 0)
end
 
// If "enthit" is a forcefield, do this
if (enthit:GetClass() == "func_wall_toggle") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Toggle", "", 0)
end
 
// If "enthit" is like a hl2 citidel tele door, do this
if (enthit:GetClass() == "momentary_rot_button") then
self.Owner:EmitSound( ShootSound )
enthit:Fire("Unlock", "", 0)
enthit:Fire("Press", "", 0.01)
end
    end
        end